<!doctype html>
<html lang="fr">
    <head>
        <meta charset="utf-8"/>
        <title>Graphique en SVG</title>
    </head>
    <body>
        <?php
        $data = array(
            'lundi' => 10, 'mardi' => 20, 'mercredi' => 30, 'jeudi' => 40, 'vendredi' => 50, 'samedi' => 60, 'dimanche' => 100,
        );
        $offsetX = 50;
        $offsetY = 50;
        $width = 1024;
        $height = 500;
        $rW = $width - ($offsetX * 2);
        $rH = $height - ($offsetY * 2);
        
        // Traitement des données
        $max = 0;
        $min = 100000000000;
        $first = true;
        foreach($data as $val){
            //$min = ($min == 0) ? $val : $min;
            $min = ($min > $val) ? $val : $min;
            $max = ($max < $val) ? $val : $max;
            $first = false;
        }
        $nbDivision = 20;
        $arrondi = 100000;
        $stepY = ($max - $min) / $nbDivision;       
        $stepY = round(($stepY < 1) ? 1 : floor($stepY * $arrondi) / $arrondi, 0, PHP_ROUND_HALF_UP);
        $startValue = ($min - $stepY) < 0 ? 0 : ($min - $stepY);
        $endValue = $stepY * ($nbDivision + 1);
        $spaceY = (int)($rH / $nbDivision);
        $spaceX = (int)($rW / count($data));
        $unite = $spaceY / $stepY;
        
        echo "<pre>Min : $min, Max : $max, StepY : $stepY, Start value : $startValue, End Value : $endValue, Space Y : $spaceY<br>Une unité est égale à $unite px</pre>";
        
        var_dump($data);
        ?>
        <svg style="width: <?php echo $width ?>px; height: <?php echo $height ?>px; border: solid 1px grey;">
            <rect x="<?php echo $offsetX ?>" y="<?php echo $offsetY ?>" width="<?php echo $rW ?>" height="<?php echo $rH ?>" style="fill: whitesmoke; stroke: lightgrey; stroke-width: 1;" />
            <!-- Y -->
            <?php 
            $x = $offsetX - 5;
            $y = $offsetY + $rH;
            for($i = $startValue; $i <= $endValue; $i+= $stepY): 
            ?>
            <rect x="<?php echo $x; ?>" y="<?php echo $y; ?>" width="5" height="2" style="fill: lightgrey; stroke: lightgrey; stroke-width: 1;" />
            <text x="<?php echo $x - 10 ?>" y="<?php echo $y; ?>" style="text-anchor: end;" title="<?php echo "$x, $y"; ?>"><?php echo $i ?></text>
            <?php 
            $y -= $spaceY;
            endfor; 
            ?>
            
            <!-- X -->
            <?php
            $x = $offsetX;
            $y = $offsetY + $rH;
            foreach($data as $key => $value):
            ?>
            <rect x="<?php echo $x; ?>" y="<?php echo $y; ?>" width="2" height="5" style="fill: lightgrey; stroke: lightgrey; stroke-width: 1;" />
            <text x="<?php echo $x; ?>" y="<?php echo $y + 20; ?>" style="text-anchor: center;" title="<?php echo "$x, $y"; ?>"><?php echo $key; ?></text>
            <?php
            $x += $spaceX;
            endforeach;
            ?>
            
            <!-- POINTS -->
            <?php
            $x = $offsetX;
            foreach($data as $value):
                $hy = ($value * $unite);
                $y = $rH - $hy + $offsetY + ($startValue * $unite);
            ?>
            <circle cx="<?php echo $x ?>" cy="<?php echo $y ?>" r="5" style="fill: blue; stroke: navy; stroke-width: 1;" title="(<?php echo "$x, $y"; ?>)" />
            <?php
            $x += $spaceX;
            endforeach;
            ?>
        </svg>
    </body>
</html>